package com.junglone;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestHikariCP {

	static Logger logger = LoggerFactory.getLogger(TestHikariCP.class);

	public static void main(String[] args) {
		int i = 100;
		while (0 < i) {			
			test();
			i--;
		}
	}

	static void test() {

		Connection connection = null;
		try {
			connection = DataSourceConfig.getInstance().getConnection();

			String strSQL = "SELECT * FROM `city_dict`;";

			PreparedStatement preparedStatement = connection.prepareStatement(strSQL);

			// connection.setAutoCommit(false);
			
			ResultSet resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				String strCityCode = resultSet.getString("city_code");
				String strCityName = resultSet.getString("city_name");
				logger.info("---------- strCityCode == {}, strCityName == {}", strCityCode, strCityName);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
		finally {
			try {
				if (null != connection) {
					// 并没有真的关闭, 只是放回了池中
					connection.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}

}
